package html;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Vector;

public class HtmlTreeNode {
    HtmlTreeNode father;
    Vector<HtmlTreeNode> children;
    private String name;

    public HtmlTreeNode(String name) {
        this.name = name;
        father = null;
        children = new Vector<HtmlTreeNode>();
    }

    /**
    *   Link together all members of a family.
    *
    *   @param pa the father
    *   @param ma the mother
    *   @param kids the children
    */
    public static void linkFamily(HtmlTreeNode pa,                              
                                  HtmlTreeNode[] kids) {
        for (HtmlTreeNode kid : kids) {
            pa.children.addElement(kid);
          
            kid.father = pa;   
        }
    }
    public static void addChild(HtmlTreeNode pa,                              
		            HtmlTreeNode kid) {

		pa.children.addElement(kid);		
		kid.father = pa;   
    }
    public static void addChildren(HtmlTreeNode pa,                              
		HtmlTreeNode[] kids) {
		for (HtmlTreeNode kid : kids) {
		pa.children.addElement(kid);
		
		kid.father = pa;   
		}
	}
    
/// getter methods ///////////////////////////////////

    public String toString() { return name; }
    public String getName() { return name; }
    public HtmlTreeNode getFather() { return father; }
    public int getChildCount() { return children.size(); }
    public HtmlTreeNode getChildAt(int i) {
        return (HtmlTreeNode)children.elementAt(i);
    }
    public int getIndexOfChild(HtmlTreeNode kid) {
        return children.indexOf(kid);
    }
    
    public int getChildIndex(HtmlTreeNode child) {
    	int n;

    	n=children.size();
    	int dem=-1;
    	for(int i=0;i<n;i++)
    	{
    		HtmlTreeNode t= children.elementAt(i);
    		if(t.getName().equals(child.getName()))
    		{
    			dem=i;
    		}
    	}
        return dem;
    }
    

}